package org.hbbTlias2025.mapper;

import org.apache.ibatis.annotations.*;
import org.hbbTlias2025.pojo.Dept;

import java.util.List;

@Mapper
public interface DeptMapper {

    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("SELECT id, `name`, create_time, update_time from dept ORDER BY update_time DESC;")
    List<Dept> findAll();

    @Delete("DELETE FROM dept WHERE id = #{id}")
    int delectOne(Integer id);

    @Insert("INSERT INTO dept(`name`, update_time, create_time) VALUES (#{name}, #{updateTime}, #{createTime});")
    int addOne(Dept dept);

    @Select("SELECT id, `name`, create_time, update_time from dept WHERE id = #{id};")
    Dept getOne(Integer id);

    @Update("UPDATE dept SET `name` = #{name}, update_time = #{updateTime} WHERE id = #{id};")
    int updateOne(Dept dept);
}
